﻿@model IEnumerable<MembershipUser>
@functions {
    private string GetProductLink(int pageNumber = 1)
    {
        var link = "/Admin/Users/Index?";

        //if (!string.IsNullOrEmpty(ViewBag.CurrentSoftField))
        //{
        //    link += "&softField=" + ViewBag.CurrentSoftField;
        //}
        //if (!string.IsNullOrEmpty(ViewBag.CurrentSoftDir))
        //{
        //    link += "&softDir=" + ViewBag.CurrentSoftDir;
        //}
        if (!string.IsNullOrEmpty(pageNumber.ToString()))
        {
            link += "&pageNumber=" + pageNumber;
        }
        return link;
    }
}
@{
    ViewBag.Title = "User management";
    Layout = "../Shared/_Layout.cshtml";
}
@*
<script type="text/javascript">
    $(document).ready(function () {
        $("#SoftField").change(function (e) {
            window.location.href = '/Admin/News?' + GetParams();
        });
        $("#SoftDir").change(function (e) {
            window.location.href = '/Admin/News?' + GetParams();
        });
    });

    function GetParams() {
        var softField = $("#SoftField :selected").val();
        var softDir = $("#SoftDir :selected").val();

        var param = '';
        if (!(softField == '' || softField == null)) {
            param += '&softField=' + softField;
        }
        if (!(softDir == '' || softDir == null)) {
            param += '&softDir=' + softDir;
        }
        return param;
    }
</script>*@
<h2>
    Index</h2>
<p>
    @Html.ActionLink("Create New", "Register", "Account")
</p>
@*<div class="adminfilterdiv">
    <ul class="productFilter">        
        <li><span>Sort By : </span><span>
            @Html.DropDownList("SoftField", (SelectList)ViewBag.SoftFields, string.Empty)
        </span></li>
        <li><span>Sort Dir : </span><span>
            @Html.DropDownList("SoftDir", (SelectList)ViewBag.SoftDir, string.Empty)
        </span></li>
    </ul>
</div>*@
<table class="dashboardTable">
    <tr>
        <th style="width: 20px;">
            User name
        </th>
        <th style="width: 200px;">
            Last login
        </th>
        <th style="width: 50px;">
            Is lock
        </th>
        <th style="width: 120px;">
            CreatedDate
        </th>
        <th style="width: 80px;">
        </th>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.UserName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.LastLoginDate)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.IsApproved)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.CreationDate)
            </td>
            <td>
                @Html.ActionLink("Change password", "ChangePasswordWithUserId", "Account", new { userId = item.ProviderUserKey }, null)
                
                @if (item.IsLockedOut)
                {
                   @:| @Html.ActionLink("Unlock", "Unlock", "Users", new { userId = item.ProviderUserKey }, null)
                }
                @if (item.IsApproved)
                {
                   @:| @Html.ActionLink("Deactivate", "ApprovalUser", "Users", new { userId = item.ProviderUserKey }, null) 
                }
                else
                {
                    @:| @Html.ActionLink("Activate", "ApprovalUser", "Users", new { userId = item.ProviderUserKey }, null) 
                }
            </td>
        </tr>
    }
</table>
<div class="common_paging">
    <ul class="nav_common_ul">
        @{
            if (ViewBag.CurrentPage > 1)
            {
                
            <li><a href="@GetProductLink()" class="common_paging_first">First</a></li>
            <li><a href="@GetProductLink((int)ViewBag.CurrentPage - 1)" class="common_paging_previous">
                Prev</a></li>
            }
            <li>page
                <input id="goToPage" type="text" class="common_pagging_page" style="width: 50px" value="@ViewBag.CurrentPage"/>
                of @ViewBag.NumberOfPage
            </li>
            if (ViewBag.CurrentPage < ViewBag.NumberOfPage)
            {
            <li><a href="@GetProductLink((int)ViewBag.CurrentPage + 1)" class="common_paging_next">
                Next</a></li>
            <li><a href="@GetProductLink((int)ViewBag.NumberOfPage)" class="common_paging_last">
                Last</a></li>
            }
        }
    </ul>
</div>
